package com.j4it.migration.modules.sys.utils;

import jade.core.Profile;
import jade.core.ProfileImpl;
import jade.core.Runtime;
import jade.wrapper.AgentController;
import jade.wrapper.ContainerController;

public class ActiveContainer {

    public static AgentController startAgent(String host, String port, String AgentName) {
        Runtime rt = Runtime.instance();
        Profile p = new ProfileImpl();
        p.setParameter(Profile.MAIN_HOST, host);
        p.setParameter(Profile.MAIN_PORT, port);
        p.setParameter(Profile.CONTAINER_NAME, "China");
        p.setParameter(Profile.AGENT_TAG, "china_");
        ContainerController cc = rt.createAgentContainer(p);
        if (null != cc) {
            try {
                Object[] obj = new Object[1];
                obj[0] = new String("");
                AgentController ac = cc.createNewAgent("%A" + AgentName, "com.j4it.migration.modules.sys.agent.BookSellerAgent", null);
                ac.start();
                return ac;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return null;
    }
}
